package com.yanu.trace.t2s.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yanu.trace.t2s.entity.User;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
public interface UserMapper extends BaseMapper<User> {
    List<User> findAll();//查询所有用户返回list
    User findByUserid(int userid);//根据userid查询用户
    List <User> findByIDL(int userid,String username);//根据用户id或者密码查询user
    int addUser(User user);//添加用户
    int findBynat(String username,String telephone);//根据用户名或者电话查询用户
    IPage<User> selectPageVo(Page<?>page);  // 分页查询

    /**
     * 多对一查询，联立user表和enterprise表，最后返回用户信息和企业信息
     * @param username
     * @return
     */
    @Select("select u.*,e.* from user u,enterprise e where u.enter_id = e.id and u.username=#{username}")
    @Results(id = "ueMapp", value = {
            @Result(column = "id",property = "id"),
            @Result(column = "enter_id",property = "enter_id"),
            @Result(column = "type",property = "type"),
            @Result(column = "name",property = "name"),
            @Result(column = "sex",property = "sex"),
            @Result(column = "telephone",property = "telephone"),
            @Result(column = "email",property = "email"),
            @Result(column = "username",property = "username"),
            @Result(column = "password",property = "password"),
            @Result(column = "hire_date",property = "hire_date"),
            @Result(column = "enter_id", property = "enterprise", one = @One(select = "com.yanu.trace.t2s.mapper.EnterpriseMapper.selectById"))
    })
    User getallinfo(String username);
}
